#include "NodeVisitor.h"

#include <iomanip>

using namespace std;

void PrintVisitor::DefaultVisit(ParseNode *n) {
	unsigned int i = depth_map[n->parent] + 1;
	depth_map[n] = i;
	(*out) << setw(i) << L"" << n->Type() << endl;

}

void PrintVisitor::visit(RootNode *n) {
	depth_map[n] = 0;
	(*out) << "Root" << endl;
}

void PrintVisitor::visit(CompilationUnitNode *n) {
	unsigned int i;
	if (!n->parent) {
		i =  0;
	}
	else {
		i = depth_map[n->parent] + 1;
	}
	depth_map[n] = i;

	(*out) << setw(i) << "" << n->Type() << endl;
}

void PrintVisitor::visit(LeafNode *n) {

	(*out) << setw(depth_map[n->parent] + 1) << "" << n->Type();
	if (n->Type() == "identifier") (*out) << " : " << n->lexeme;
	(*out) << endl;
}

void PrintVisitor::visit(IntegerLiteralNode *n) {
	(*out) << setw(depth_map[n->parent] + 1) << "" << n->Type() << " : " << n->value << endl;
}
void PrintVisitor::visit(BooleanLiteralNode *n) {
	(*out) << setw(depth_map[n->parent] + 1) << "" << n->Type() << " : " << (n->value ? "true" : "false") << endl;
}
void PrintVisitor::visit(CharacterLiteralNode *n) {
	(*out) << setw(depth_map[n->parent] + 1) << "" << n->Type() << " : " << n->value << endl;
}
void PrintVisitor::visit(StringLiteralNode *n) {
	(*out) << setw(depth_map[n->parent] + 1) << "" << n->Type() << " : " << n->value << endl;
}

